#include "YGContext.h"

#include "YGEvent.h"
#include "YGEventListener.h"

namespace YoghurtGum
{

	Context* Context::s_Instance = NULL;

	Context::Context()
	{
		
	}
	
	Context::~Context()
	{
		
	}

	Context& Context::Get()
	{
		if (!s_Instance) { s_Instance = new Context(); }
		return *s_Instance;
	}

	void Context::SetEventListener(const char* a_Event, EventListener* a_Listener)
	{
		if (!strcmp(a_Event, "OnResize"))
		{
			m_ListenerOnResize = a_Listener;
		}
		else if (!strcmp(a_Event, "OnUpdate"))
		{
			m_ListenerOnUpdate = a_Listener;
		}

		m_EventListeners.push_back(a_Listener);
	}

	void Context::PushEvent(const char* a_Name, const Dict& a_Arguments)
	{
		Event* current = new Event(a_Name, a_Arguments);

		m_Events.push_back(current);
	}

	void Context::HandleEvents()
	{
		for (std::vector<Event*>::iterator it = m_Events.begin(); it != m_Events.end(); it++)
		{
			for (std::vector<EventListener*>::iterator jt = m_EventListeners.begin(); jt != m_EventListeners.end(); jt++)
			{
				(*jt)->Process(*(*it));
			}
		}

		m_Events.clear();
	}

}; // namespace YoghurtGum